﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.Windows.Media.Imaging;
using System.IO;

namespace BackgroundTransferServiceSample
{
    public partial class DisplayDownloadedFiles : PhoneApplicationPage
    {
        List<BitmapImage> ImageList = new List<BitmapImage>();
        public DisplayDownloadedFiles()
        {
            InitializeComponent();
            IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication();
            string[] strFileNames = isoFile.GetFileNames("\\Shared\\Transfers\\*");
            if (!isoFile.DirectoryExists("Transfers"))
            {
                isoFile.CreateDirectory("Transfer");
            }

            for (int i = 0; i < strFileNames.Length; i++)
            {
                BitmapImage bitmap = new BitmapImage();
                using (IsolatedStorageFileStream isoFileStream = new IsolatedStorageFileStream("/shared/transfers/" + strFileNames[i], FileMode.Open, isoFile))
                {
                    bitmap.SetSource(isoFileStream);
                    ImageList.Add(bitmap);
                    isoFileStream.Close();
                }
            }
            lstBoxDisplayImage.ItemsSource = ImageList;
        }
    }
}
